import express from "express";
import cors from "cors";
import abcRouter from './router/abc.js'
import { PrismaClient } from '@prisma/client'

const app = express()
app.use(cors())
app.use(express.json())
app.use(express.urlencoded({ extended: true }))

const db = new PrismaClient()
// 配置自己的中间件
app.use((req, res, next) => {
    req.db = db;
    res.success = (data, info) => {
        res.send({ success: true, data, info })
    }
    res.fail = (info) => {
        res.send({ success: true, data, info })
    }
    next()
})


//路由
app.use(abcRouter)

app.listen(3000, () => {
    console.log('app is running at port 3000');
})